/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Gestion_BDD;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Dna
 */
public class GestionBDD {
    private Connection con;
    //Connection
    public void connection()
    {
        String url = "jdbc:mysql://127.0.0.1:3306/mydb";
        String user = "root";
        String password = null;
        try {
            con = DriverManager.getConnection(url, user, password);
        } catch (SQLException ex) {
            Logger.getLogger(GestionBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    //Execute une requete de type select
    public ResultSet Requete(String requete)
    {
        String queryString = requete;
        Statement stmt;
        ResultSet rs;
        try {
            stmt = con.createStatement();
             rs = stmt.executeQuery(queryString);
             return rs;
        } catch (SQLException ex) {
            Logger.getLogger(GestionBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;      
    }
    //Execute une requete de type Update//Insert ou Delete
    public int RequeteInsert(String requete)
    {
        String queryString = requete;
        Statement stmt;
        int rs;
        try {
            stmt = con.createStatement();
            rs = stmt.executeUpdate(queryString);
             return rs;
        } catch (SQLException ex) {
            Logger.getLogger(GestionBDD.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;      
    }
    
}
